package com.suarte.webapp.action;

import com.suarte.core.Resolution;
import com.suarte.core.WorkType;
import com.suarte.core.service.ProductManager;
import java.io.Serializable;
import java.util.List;
import org.appfuse.service.GenericManager;

/**
 * @date   Jan 16, 2011
 * @author Gcastillo
 */
public class ProductList extends BasePage implements Serializable {

    private ProductManager productManager;
    private GenericManager<Resolution, Long> resolutionManager;
    private GenericManager<WorkType, Long> workTypeManager;
    private List products;
    private String code;
    private String description;
    private Resolution resolution;
    private WorkType workType;

    public void setProductManager(ProductManager productManager) {
        this.productManager = productManager;
    }

    public void setResolutionManager(GenericManager<Resolution, Long> resolutionManager) {
        this.resolutionManager = resolutionManager;
    }

    public void setWorkTypeManager(GenericManager<WorkType, Long> workTypeManager) {
        this.workTypeManager = workTypeManager;
    }

    public ProductList() {
        setSortColumn("id"); // sets the default sort column
    }

    public String execute() {
        products = productManager.findProducts(code, description, resolution, workType);
        return "list";
    }

    public List getProducts() {
        products = productManager.findProducts(code, description, resolution, workType);
        if (products != null) {
            return sort(products);
        } else {
            return products;
        }
    }

    public void setProducts(List products) {
        this.products = products;
    }

    public List<Resolution> getResolutions() {
        return resolutionManager.getAll();
    }

    public List<WorkType> getWorkTypes() {
        return workTypeManager.getAll();
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Resolution getResolution() {
        return resolution;
    }

    public void setResolution(Resolution resolution) {
        this.resolution = resolution;
    }

    public WorkType getWorkType() {
        return workType;
    }

    public void setWorkType(WorkType workType) {
        this.workType = workType;
    }
}
